/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sk.robocup.dvanastyhrac.tactics;

import robocup.component.tactics.AbstractState.STATES;
import robocup.component.tactics.InterceptOpponentState;
import robocup.component.tactics.StateEvaluation;
import sk.robocup.dvanastyhrac.actionfactories.AttentionToActionFactory12;

/**
 *
 * @author me
 */
public class InterceptOpponentState12 extends InterceptOpponentState {

    public InterceptOpponentState12(StateEvaluation parent) {

        super(parent);
        this.state = STATES.INTERCEPT_OPPONENT;

    }

    /**
     * Never go when fastest to ball as this is handled by the
     * {@link InterceptBallState}.
     * Always go when fastest teammate to intercept the opponent.
     *
     * (This is a very simple version. Add your logic here!)
     */
    @Override
    public boolean preCondition() {

        if (!this.checkPlayMode() || !this.getBall().isReliable() || this.getPlayer().canKick(getWorld().getBallRef()) || (this.getProphet().getFastestTeammateToBall() != null &&
                this.getProphet().getFastestTeammateToBall().isMe())) {
            return false;
        }

        //closest to ball or near to ball
        return this.getWorld().getClosestPlayerTo(this.getWorld().getTeammates(),
                this.getWorld().getBallRef().getPosition(), true).isMe() || this.getWorld().getBallRef().getDistance(this.getWorld().getSelfRef()) < 5;
    }

    @Override
    public void calculateAttentionToAction() {
        this.attentionToAction = AttentionToActionFactory12.getAttentionToAction(this);

        //if we got null, compute default
        if (this.attentionToAction == null) {
            super.calculateAttentionToAction();
        }
    }
}
